const path = require('path')
function resolve (dir) {
  return path.join(__dirname, dir)
}

let proxyObj = {}
proxyObj['/'] = {
  // websocket
  ws: false,
  // 目标地址
  target: 'http://localhost:8081',
  // 发送请求头host会被设置成target
  changeOrigin: true,
  pathReWrite: {
    '^/': '/'
  }
}
const commonConfig = {
  chainWebpack: config => {
    config.resolve.alias.set('@', resolve('src'))
    config.resolve.alias.set('@assets', resolve('src/assets'))
    config.resolve.alias.set('@components', resolve('src/components'))
    config.resolve.alias.set('@store', resolve('src/store'))
    config.resolve.alias.set('@utils', resolve('src/utils'))
    config.resolve.alias.set('@views', resolve('src/views'))
    config.resolve.alias.set('@constants', resolve('src/constants'))
    config.resolve.alias.set('@config', resolve('src/config'))
    config.resolve.alias.set('@core', resolve('src/core'))
    config.resolve.alias.set('@api', resolve('src/api'))
    config.resolve.alias.set('@service', resolve('src/service'))
  },
  devServer: {
    host: 'localhost',
    port: 8080,
    proxy: proxyObj
  }
}
module.exports = commonConfig